package com.crm.controller;

import com.crm.common.annotation.Log;
import com.crm.common.enums.BusinessType;
import com.crm.common.result.AjaxResult;
import com.crm.common.result.PageResult;
import com.crm.dto.CourseDto;
import com.crm.dto.OperLogDto;
import com.crm.service.OperLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/monitor/operlog")
public class SysOperLogController {
    @Autowired
    private OperLogService  operLogService;

    //分页查询操作日志列表
    @GetMapping("/list")
    @Log(title = "操作日志管理", businessType = BusinessType.EXPORT)
    public PageResult list(OperLogDto operLogDto ){
        log.info("开始查询操作日志列表：{}",operLogDto);
        return operLogService.PageList(operLogDto);
    }

    /**
     * 批量删除系统操作日志
     */

    @DeleteMapping("{ids}")
    @Log(title = "操作日志管理", businessType = BusinessType.DELETE)
    public AjaxResult deleteOperLogByIds(List<Long> ids){
        log.info("删除操作日志：{}",ids);
        operLogService.removeBatchByIds(ids);
        return AjaxResult.success();
    }

    /**
     * 清空操作日志
     */
    @DeleteMapping("/clean")
    @Log(title = "操作日志管理", businessType = BusinessType.CLEAN)
    public AjaxResult clean(){
        log.info("清空操作日志");
        operLogService.cleanOperLog();
        return AjaxResult.success();
    }
}
